package com.hbnu.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hbnu.system.config.BaseException;
import com.hbnu.system.constant.RoleConstant;
import com.hbnu.system.constant.StatusCheckConstant;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.mapper.AchievementMapper;
import com.hbnu.system.model.context.BaseContext;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.entity.*;
import com.hbnu.system.model.query.AchievementPageQuery;
import com.hbnu.system.model.vo.AchievementVO;
import com.hbnu.system.service.*;
import com.hbnu.system.utils.CheckAuditHelper;
import com.hbnu.system.utils.CheckRoleUtil;
import com.hbnu.system.utils.UserInfoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 科研成果表(Achievement)表服务实现类
 *
 * @author makejava
 * @since 2025-07-21 15:59:42
 */
@Service
public class AchievementServiceImpl extends ServiceImpl<AchievementMapper, Achievement> implements AchievementService {
    @Autowired
    private IUserService iUserService;

    @Autowired
    private IDeptService iDeptService;

    @Autowired
    private IdToStatsService idToStatsService;

    @Autowired
    private AchievementFileService achievementfileService;

    @Autowired
    private IAuthorityService iAuthorityService;

    @Autowired
    private AuditService auditService;

    @Autowired
    private AchievementMapper achievementMapper;

    @Autowired
    private AchievementAuthorService achievementAuthorService;

    @Autowired
    private AchievementQualificationService achievementQualificationSerivce;

    @Autowired
    private CheckRoleUtil checkRoleUtil;

    @Autowired
    private UserInfoUtils userInfoUtils;

    @Autowired
    private CheckAuditHelper checkAuditHelper ;
    /**
     * 添加科研成果
     * @param
     * @return
     */
    @Override
    public boolean addAchievement(Achievement achievement) {

        checkAddAchievement(achievement);
        achievement.setStatus("草稿");
        achievement.setEnteredTime(LocalDateTime.now());

        return baseMapper.insert(achievement) == 1;
    }

    public  void  checkAddAchievement(Achievement achievement){
        if(StrUtil.isEmpty(achievement.getName()) || StrUtil.isBlank(achievement.getName())){
            throw new BaseException("请输入科研成果名称");
        }
        if (StrUtil.isEmpty(achievement.getDiscipline()) || StrUtil.isBlank(achievement.getDiscipline())){
            throw new BaseException("请输入一级学科");
        }
        if(StrUtil.isEmpty(achievement.getResultForm()) || StrUtil.isBlank(achievement.getResultForm())){
            throw new BaseException("请输入成果形式");
        }
        if(StrUtil.isEmpty(achievement.getLevel()) || StrUtil.isBlank(achievement.getLevel())){
            throw new BaseException("请输入级别");
        }
        if(StrUtil.isEmpty(achievement.getInstitution()) || StrUtil.isBlank(achievement.getInstitution())){
            throw new BaseException("请输入所属机构");
        }
        if (StrUtil.isEmpty(achievement.getFirstAuthor()) || StrUtil.isBlank(achievement.getFirstAuthor())){
            throw new BaseException("请输入第一作者");
        }
        if(achievement.getIsApproved()!=null){
            if(achievement.getIsApproved()==1){
                if(StrUtil.isEmpty(achievement.getApprovedLeader()) || StrUtil.isBlank(achievement.getApprovedLeader())){
                    throw new BaseException("请输入领导签名");
                }
            }
        }
        if(achievement.getIsAdopted()!=null){
            if(achievement.getIsAdopted()==1){
                if(StrUtil.isEmpty(achievement.getAdoptedDepartment()) || StrUtil.isBlank(achievement.getAdoptedDepartment())){
                    throw new BaseException("请输入部门");
                }
            }
        }
        if(StrUtil.isEmpty(achievement.getEntered())|| StrUtil.isBlank(achievement.getEntered())){
            throw new BaseException("请输入录入人");
        }
        if(StrUtil.isEmpty(achievement.getAdoptionTime().toString())|| StrUtil.isBlank( achievement.getAdoptionTime().toString())){
            throw new BaseException("请输入采纳/签批时间");
        }

    }

    /**
     * 删除科研成果
     * @param achievementID
     * @return
     */
    @Override
    public boolean deleteAchievement(String achievementID) throws IOException {
        Achievement achievement = super.getOne(Wrappers.lambdaQuery(Achievement.class)
                .eq(Achievement::getId, achievementID));
        //校验普通用户权限不能修改当前状态信息
        checkRoleUtil.checkPermissionAchievement(achievement.getStatus());

        // 删除科研成果关联的作者根据科研成果id
        achievementAuthorService.remove(Wrappers.lambdaQuery(AchievementAuthor.class)
                .eq(AchievementAuthor::getAchievementId, achievementID));

        // 删除科研成果关联的文件信息根据科研成果id
        achievementfileService.remove(Wrappers.lambdaQuery(AchievementFile.class)
                .eq(AchievementFile::getAchievementid, achievementID));

        //删除科研成果关联的量化分数根据咨询报告id
        achievementQualificationSerivce.remove(Wrappers.lambdaQuery(AchievementQualification.class)
                .eq(AchievementQualification::getAchievementId, achievementID));

        // 删除科研成果关联的文件信息
        // 1. 根据科研成果ID查询出所有的文件信息ID
        List<AchievementFile> achievementFiles = achievementfileService.list(Wrappers.lambdaQuery(AchievementFile.class)
                .eq(AchievementFile::getAchievementid, achievementID));
        // 2. 拿到ID集合
        List<String> fileIds = achievementFiles.stream()
                .map(AchievementFile::getFileid)
                .collect(Collectors.toList());
        // 3. 删除文件
        for (String fileId : fileIds) {
            achievementfileService.deletAchievementFile(fileId);
        }

        // 删除审核记录根据科研成果ID
        auditService.remove(Wrappers.lambdaQuery(Audit.class)
                .eq(Audit::getSynthesisID, achievementID));

        // 最后删除科研成果本身
        return baseMapper.deleteById(achievementID) == 1;

    }

    private Boolean updateAchievementByEntity(Achievement achievement) {
        return baseMapper.updateById(achievement) == 1;
    }

    /**
     * 修改科研成果信息
     * @param achievement
     * @return
     */
    @Override
    public boolean updateAchievement(Achievement achievement) {
        //校验普通用户权限不能修改当前状态信息
        checkRoleUtil.checkPermissionAchievement(achievement.getStatus());

//        checkupdateAchievement(achievement);
        checkAddAchievement(achievement);

        //判断该科研成果名是否被使用
        Achievement one = super.getOne(Wrappers.lambdaQuery(Achievement.class)
                .eq(Achievement::getName, achievement.getName())
                .ne(Achievement::getId, achievement.getId()));
        if (Objects.nonNull(one)) {
            throw new BaseException("该科研成果名称已被使用");
        }

        return baseMapper.updateById(achievement) == 1;

    }

    /**
     * 根据科研成果ID查询科研成果
     * @param achievementID
     * @return
     */
    @Override
    public Achievement getAchievementById(String achievementID) {
        Achievement achievement = super.getOne(Wrappers.lambdaQuery(Achievement.class)
                .eq(Achievement::getId, achievementID));
        if(Objects.isNull(achievement)){
            throw new BaseException("咨询报告编号异常!");
        }
        return achievement;
    }


    /**
     * 检查科研成果名称
     * @param achievement_name
     * @return
     */
    @Override
    public boolean checkAchievementName(String achievement_name) {
        Achievement one = super.getOne(Wrappers.lambdaQuery(Achievement.class)
                .eq(Achievement::getName, achievement_name));
        if(Objects.nonNull(one)){
            throw new BaseException("该科研成果名称已存在!");
        }
        return true;
    }


    /**
     * 院级科研成果审核通过
     * @param token
     * @param PaID
     * @return
     */
    @Override
    public Boolean collegeCheckPass(String token,String PaID) {
        Achievement achievement = getAchievementById(PaID);
        if (Objects.isNull(achievement)){
            throw new BaseException("该科研成果编号有误!");
        }
        if(!achievement.getStatus().equals("待院级审核")){
            throw new BaseException("该科研成果状态不处于该环节!");
        }

        String roleName = userInfoUtils.getCurrentUserInfo().getRoleName();
        //目标状态
        String targetStatus = StatusCheckConstant.COLLEGE_CHECK_PEOPLE.equals(roleName)
                ? StatusCheckConstant.WAIT_SCHOOL_CHECK
                : StatusCheckConstant.CHECK_PASS;
        String id= String.valueOf(achievement.getId());

        return checkAuditHelper.doPassAudit(
                achievement,
                StatusCheckConstant.WAIT_COLLEGE_CHECK,
                targetStatus,
                roleName,
                "咨询报告",
                achievement::getId,
                achievement::getStatus,
                achievement::setStatus,
                this::updateAchievementByEntity
        );
//
//        InfoVO info = JwtUtils.getInfo(token);
//        String[] strings = new String[1];
//        strings[0] = iAuthorityService.getById(info.getRoles()[0]).getText();
//        User user = iUserService.getById(info.getUid());
//        String role = strings[0];
//        role=role.equals("院级审核员")?("19185212210"):("19190251173");
//        String name = user.getName();
//
//        Audit audit = new Audit();
//        audit.setSynthesisID(PaID);
//        audit.setAuditerRole(role);
//        audit.setAuditerName(name);
//
//        if(role.equals("19185212210")){
//            audit.setStatusChange("科研成果待院级审核->院级审核通过");
//            achievement.setStatus("待校级审核");
//        }else if(role.equals("19190251173")){
//            audit.setStatusChange("科研成果待院级审核->校级审核通过");
//            achievement.setStatus("审核通过");
//        }
//        audit.setAuditOpinion("通过");
//        audit.setAuditerTime(LocalDateTime.now());
//        auditService.addAudit(audit);
//        return baseMapper.updateById(achievement) == 1;
    }

    /**
     * 院级科研成果审核驳回
     * @param token
     * @param checkBackDTO
     * @return
     */
    @Override
    public Boolean collegeCheckBack(String token, CheckBackDTO checkBackDTO) {
        String id = checkBackDTO.getID();
        Achievement achievement = getAchievementById(id);
        if (Objects.isNull(achievement)){
            throw new BaseException("该科研成果编号有误!");
        }
        String roleName = userInfoUtils.getCurrentUserInfo().getRoleName();
        String backStatus = StatusCheckConstant.COLLEGE_CHECK_PEOPLE.equals(roleName)
                ? StatusCheckConstant.COLLEGE_CHECK_BACK
                : StatusCheckConstant.SCHOOL_CHECK_BACK;

        return checkAuditHelper.doBackAudit(
                achievement,
                StatusCheckConstant.WAIT_COLLEGE_CHECK,
                backStatus,
                checkBackDTO.getReason(),
                "咨询报告",
                achievement::getId,
                achievement::getStatus,
                achievement::setStatus,
                achievement::setReason,
                this::updateAchievementByEntity
        );
        
//        if(!achievement.getStatus().equals("待院级审核")){
//            throw new BaseException("该科研成果状态不处于该环节!");
//        }

//        achievement.setReason(checkBackDTO.getReason());
//        InfoVO info = JwtUtils.getInfo(token);
//        String[] strings = new String[1];
//        strings[0] = iAuthorityService.getById(info.getRoles()[0]).getText();
//        User user = iUserService.getById(info.getUid());
//        String role = strings[0];
//        role=role.equals("院级审核员")?("19185212210"):("19190251173");
//        String name = user.getName();
//
//        Audit audit = new Audit();
//        audit.setSynthesisID(checkBackDTO.getID());
//        audit.setAuditOpinion(checkBackDTO.getReason());
//        audit.setAuditerRole(role);
//        audit.setAuditerName(name);
//
//        if(role.equals("19185212210")){
//            audit.setStatusChange("科研成果待院级审核->被院级退回");
//            achievement.setStatus("被院级退回");
//        }else if(role.equals("19190251173")){
//            audit.setStatusChange("科研成果待院级审核->被校级退回");
//            achievement.setStatus("被校级退回");
//        }
//        audit.setAuditerTime(LocalDateTime.now());
//        auditService.addAudit(audit);
//        return baseMapper.updateById(achievement) == 1;
    }

    /**
     * 校级科研成果审核通过
     * @param token
     * @param PaID
     * @return
     */
    @Override
    public Boolean schoolCheckPass(String token,String PaID) {
        Achievement achievement = getAchievementById(PaID);
        if (Objects.isNull(achievement)){
            throw new BaseException("该科研成果编号有误!");
        }

        String currentStatus = achievement.getStatus();
        if (!StatusCheckConstant.WAIT_SCHOOL_CHECK.equals(currentStatus)
                && !StatusCheckConstant.WAIT_COLLEGE_CHECK.equals(currentStatus)) {
            throw new BaseException("该咨询报告状态不处于该环节!");
        }

        String roleName = userInfoUtils.getCurrentUserInfo().getRoleName();

        return checkAuditHelper.doPassAudit(
                achievement,
                currentStatus, // 当前状态可为学院或学校待审核
                StatusCheckConstant.CHECK_PASS,
                roleName,
                "咨询报告",
                achievement::getId,
                achievement::getStatus,
                achievement::setStatus,
                this::updateAchievementByEntity
        );
//        if(!achievement.getStatus().equals("待校级审核") && !achievement.getStatus().equals("待院级审核")){
//            throw new BaseException("该科研成果状态不处于该环节!");
//        }
//        achievement.setStatus("审核通过");
//        InfoVO info = JwtUtils.getInfo(token);
//        String[] strings = new String[1];
//        strings[0] = iAuthorityService.getById(info.getRoles()[0]).getText();
//        User user = iUserService.getById(info.getUid());
//        String role = strings[0];
//        role=role.equals("院级审核员")?("19185212210"):("19190251173");
//        String name = user.getName();
//
//
//        Audit audit = new Audit();
//        audit.setSynthesisID(PaID);
//        audit.setAuditerRole(role);
//        audit.setAuditerName(name);
//        audit.setStatusChange("科研成果待校级审核->校级审核通过");
//        audit.setAuditOpinion("通过");
//        audit.setAuditerTime(LocalDateTime.now());
//        auditService.addAudit(audit);
//        return baseMapper.updateById(achievement) == 1;
    }

    /**
     * 校级科研成果审核驳回
     * @param token
     * @param checkBackDTO
     * @return
     */
    @Override
    public Boolean schoolCheckBack(String token,CheckBackDTO checkBackDTO) {
        String id = checkBackDTO.getID();
        Achievement achievement = getAchievementById(id);
        if (Objects.isNull(achievement)){
            throw new BaseException("该科研成果编号有误!");
        }
        String currentStatus = achievement.getStatus();
        if (!StatusCheckConstant.WAIT_SCHOOL_CHECK.equals(currentStatus)
                && !StatusCheckConstant.WAIT_COLLEGE_CHECK.equals(currentStatus)) {
            throw new BaseException("该咨询报告状态不处于该环节!");
        }

        String roleName = userInfoUtils.getCurrentUserInfo().getRoleName();

        return checkAuditHelper.doBackAudit(
                achievement,
                currentStatus,
                StatusCheckConstant.SCHOOL_CHECK_BACK,
                checkBackDTO.getReason(),
                "咨询报告",
                achievement::getId,
                achievement::getStatus,
                achievement::setStatus,
                achievement::setReason,
                this::updateAchievementByEntity
        );
//        if(!achievement.getStatus().equals("待校级审核") && !achievement.getStatus().equals("待院级审核")){
//            throw new BaseException("该科研成果状态不处于该环节!");
//        }
//        achievement.setStatus("被校级退回");
//        achievement.setReason(checkBackDTO.getReason());
//        InfoVO info = JwtUtils.getInfo(token);
//        String[] strings = new String[1];
//        strings[0] = iAuthorityService.getById(info.getRoles()[0]).getText();
//        User user = iUserService.getById(info.getUid());
//        String role = strings[0];
//        role=role.equals("院级审核员")?("19185212210"):("19190251173");
//        String name = user.getName();
//
//        Audit audit = new Audit();
//        audit.setSynthesisID(checkBackDTO.getID());
//        audit.setAuditOpinion(checkBackDTO.getReason());
//        audit.setAuditerRole(role);
//        audit.setAuditerName(name);
//        audit.setStatusChange("科研成果待校级审核->被校级退回");
//        audit.setAuditerTime(LocalDateTime.now());
//        auditService.addAudit(audit);
//        return baseMapper.updateById(achievement) == 1;
    }

    @Override
    public Boolean ReCommitAchievement(String achievementID) {
        Achievement achievement = super.getOne(Wrappers.lambdaQuery(Achievement.class).eq(Achievement::getId, achievementID));
        if(Objects.isNull(achievement)){
            throw new BaseException("科研成果编号有误!");
        }

        if(!achievement.getStatus().equals("草稿") && !achievement.getStatus().equals("被院级退回") && !achievement.getStatus().equals("被校级退回")){
            throw new BaseException("该科研成果不适用于该阶段!");
        }

        checkAddAchievement( achievement);

        // 检查量化分数是否填写
        AchievementQualification qualification = achievementQualificationSerivce.getOne(
                Wrappers.lambdaQuery(AchievementQualification.class)
                        .eq(AchievementQualification::getAchievementId, achievement.getId())
        );
        if (Objects.isNull(qualification)) {
            throw new BaseException("请先填写科研成果的量化分数!");
        }

        // 检查作者列表是否填写
        List<AchievementAuthor> authorList = achievementAuthorService.list(
                Wrappers.lambdaQuery(AchievementAuthor.class)
                        .eq(AchievementAuthor::getAchievementId, achievement.getId())
        );
        if (CollectionUtils.isEmpty(authorList)) {
            throw new BaseException("请先添加科研成果的作者信息!");
        }

        achievement.setStatus("待院级审核");
        achievement.setReason("");

        return baseMapper.updateById(achievement)==1;
    }
    
    @Override
    public Boolean withdrawAchievement(String token, String achievementID) {
        Achievement achievement = getById(achievementID);
        if(achievement==null){
            throw new BaseException("该科研成果不存在!");
        }
        
        // 检查状态是否可以撤回
        String currentStatus = achievement.getStatus();
        if (!"待院级审核".equals(currentStatus)) {
            throw new BaseException("该科研成果状态不允许撤回!");
        }
        
        // 更新状态为草稿
        achievement.setStatus("草稿");
        achievement.setReason("用户主动撤回");
        
        // 添加审计记录
        String currentId = BaseContext.getCurrentId();
        User byId = iUserService.getById(currentId);
        Audit audit = new Audit();
        audit.setSynthesisID(achievementID);
        audit.setAuditOpinion("用户主动撤回");
        audit.setAuditerRole(byId.getRole());
        audit.setAuditerName(byId.getName());
        audit.setStatusChange(currentStatus + "->草稿");
        audit.setAuditerTime(LocalDateTime.now());
        auditService.addAudit(audit);
        
        return updateById(achievement);
    }


    /**
     * 获取用户关联的科研成果
     * @param achievementPageQuery
     * @return
     */
    @Override
    public CommonPage<AchievementVO> userGetRelateAchievement(AchievementPageQuery achievementPageQuery) {
        String userId = BaseContext.getCurrentId();
        User user = iUserService.getById(userId);
        String role = user.getRole();

        // 创建MyBatis-Plus的Page对象
        Page<AchievementVO> page = new Page<>(achievementPageQuery.getPageNum(), achievementPageQuery.getPageSize());
        IPage<AchievementVO> achievementIPage = null;
        // 根据角色执行不同查询
        if (role.equals(RoleConstant.ROLE_ADMIN_SCHOOL)) {
            achievementIPage = achievementMapper.schoolGetRelateAchievementQuery(page, achievementPageQuery, user);
        } else if (role.equals(RoleConstant.ROLE_ADMIN_COLLEGE)) {
            achievementIPage = achievementMapper.collegeGetRelateAchievementQuery(page, achievementPageQuery, user);
        } else {
            achievementIPage = achievementMapper.userGetRelateAchievementQuery(page, achievementPageQuery, user);
        }
        // 初始化量化分数
        float figure = 0;

        // 查询咨询报告关联的作者
        // 遍历记录，计算量化分数
        List<AchievementVO> records = achievementIPage.getRecords();
        for (AchievementVO record : records) {
            if (record.getStatus().equals("审核通过")){
                figure += record.getScore();
            }
        }

        // 构造返回分页对象
        CommonPage<AchievementVO> achievementCommonPage = CommonPage.restPage(achievementIPage);
        achievementCommonPage.setFigure(figure);
        achievementCommonPage.setList(records);

        return achievementCommonPage;
    }

    @Override
    public CommonPage<Achievement> export(AchievementPageQuery achievementPageQuery) {
        String userId = BaseContext.getCurrentId();
        User user = iUserService.getById(userId);
        String role = user.getRole();

        Page<Achievement> page = new Page<>(achievementPageQuery.getPageNum(), achievementPageQuery.getPageSize());
        IPage<Achievement> achievementIPage;

        if (RoleConstant.ROLE_ADMIN_SCHOOL.equals(role)) {
            achievementIPage = achievementMapper.schoolExportRelateAchievementQuery(page, achievementPageQuery, user);
        } else if (RoleConstant.ROLE_ADMIN_COLLEGE.equals(role)) {
            achievementIPage = achievementMapper.collegeExportRelateAchievementQuery(page, achievementPageQuery, user);
        } else {
            achievementIPage = achievementMapper.userExportRelateAchievementQuery(page, achievementPageQuery, user);
        }

        List<Achievement> records = achievementIPage.getRecords();
        System.out.println("records==="+records);
        float figure = 0;
        for (Achievement record : records) {
            if (StatusCheckConstant.CHECK_PASS.equals(record.getStatus())) {
                String scoreStr = record.getScore();
                float score = 0.0f; // 默认值，根据业务需求调整
                if (scoreStr != null && !scoreStr.trim().isEmpty()) {
                    // 仅当字符串非空且非空白时才转换
                    score = Float.parseFloat(scoreStr);
                }
                figure += score;
            }

            User user1 = iUserService.getById(record.getEntered());
            record.setEntered(user1.getName());

//            // 查询第一作者/共同第一作者
//            List<AchievementAuthor> leadAuthors = achievementAuthorService.list(Wrappers.lambdaQuery(AchievementAuthor.class)
//                    .eq(AchievementAuthor::getAchievementId, record.getId())
//                    .in(AchievementAuthor::getAuthortype, Arrays.asList("第一作者", "共同第一作者")));
//            record.setLeaduthor(leadAuthors.stream().map(AchievementAuthor::getName).collect(Collectors.joining(",")));
//
//            // 查询通讯作者
//            List<AchievementAuthor> contactAuthors = iAchievementAuthorService.list(Wrappers.lambdaQuery(AchievementAuthor.class)
//                    .eq(AchievementAuthor::getAchievementID, record.getAchievementID())
//                    .eq(AchievementAuthor::getAuthortype, "通讯作者"));
//            record.setCorrespondingAuthor(contactAuthors.stream().map(AchievementAuthor::getName).collect(Collectors.joining(",")));

//            // 查询关联项目
//            List<Achievementproject> achievementProjects = iachievementprojectService.list(Wrappers.lambdaQuery(Achievementproject.class)
//                    .eq(Achievementproject::getAchievementID, record.getAchievementID()));
//            record.setAssociatedprojects(achievementProjects.stream().map(Achievementproject::getProjectName).collect(Collectors.joining(",")));
            //转化allAuthors
            List<AchievementAuthor> achievementAuthors = achievementAuthorService.listAuthor(record.getId());
            String authorNames = achievementAuthors == null ? "" :
                    achievementAuthors.stream()
                            // 过滤掉列表中可能存在的null对象
                            .filter(Objects::nonNull)
                            // 提取每个作者的name字段
                            .map(AchievementAuthor::getName)
                            // 过滤掉name为null的情况
                            .filter(Objects::nonNull)
                            // 用逗号拼接所有name
                            .collect(Collectors.joining(","));
            record.setAllAuthor(authorNames);
//            String allAuthor = idToStatsService.IdToAllauthor(record.getAllAuthor());

        }

        CommonPage<Achievement> achievementCommonPage = CommonPage.restPage(achievementIPage);
        achievementCommonPage.setFigure(figure);
        achievementCommonPage.setList(records);
        System.out.println("records="+records);
        return achievementCommonPage;
    }
}

